﻿using System;

namespace LogNaga
{
	/// <summary>
	/// 把exception转换为string格式记录
	/// </summary>
	/// <param name="exception"><see cref="Exception"/>异常实例</param>
	/// <returns>string格式的exception</returns>
	public delegate string ExceptionFormatter(Exception exception);

	/// <summary>
	/// 用于返回默认的<see cref="ExceptionFormantter"/>实例
	/// </summary>
	public static class ExceptionFormatterHelper
	{
		private static ExceptionFormatter defaultEf =
			ex => string.Format("{0} | {1}\r\n{2}\r\n{3}\r\n", DateTime.Now.ToString(), ex.Message, ex.Source, ex.StackTrace);

		/// <summary>
		/// 获取默认的<see cref="ExceptionFormantter"/>实例
		/// </summary>
		public static ExceptionFormatter Default
		{
			get
			{
				return defaultEf;
			}
		}
	}
}
